﻿namespace HySoft.Cash.DB
{
    using Huayou.Common.Database;
    using Huayou.Utils;
    using HySoft.Cash.BaseClass;
    using HySoft.Cash.Structure;
    using System;
    using System.Data;

    public class TemppaymentDB : BaseDB
    {
        public TemppaymentDB(DBOperate oper) : base(oper)
        {
        }

        public bool Add(TemppaymentDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { 
                "INSERT INTO tEmpPayment (EmpSid,BankSid,PaymentDate,PaymentAmount,PaymentDD,PaymentMM,PaymentYY,OrgSid) VALUES (", detail.EmpSid, ",", detail.BankSid, ",'", StringUtils.ToSQL(detail.PaymentDate), "',", detail.PaymentAmount, ",'", StringUtils.ToSQL(detail.PaymentDD), "','", StringUtils.ToSQL(detail.PaymentMM), "','", StringUtils.ToSQL(detail.PaymentYY), "',", detail.OrgSid, 
                ")"
             });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Delete(int Sid)
        {
            int num = 0;
            string strSql = "DELETE FROM tEmpPayment where (Sid=" + Sid + ")";
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Edit(TemppaymentDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { 
                "UPDATE tEmpPayment set EmpSid=", detail.EmpSid, ",BankSid=", detail.BankSid, ",PaymentDate='", StringUtils.ToSQL(detail.PaymentDate), "',PaymentAmount=", detail.PaymentAmount, ",PaymentDD='", StringUtils.ToSQL(detail.PaymentDD), "',PaymentMM='", StringUtils.ToSQL(detail.PaymentMM), "',PaymentYY='", StringUtils.ToSQL(detail.PaymentYY), "',OrgSid=", detail.OrgSid, 
                " where (Sid=", detail.Sid, ")"
             });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public TemppaymentDT Get(int Sid)
        {
            TemppaymentDT tdt = new TemppaymentDT();
            try
            {
                try
                {
                    string strSql = "select * from tEmpPayment where (Sid=" + Sid + ")";
                    DataTable table = base.ExecuteForDataTable(strSql);
                    DataRow row = null;
                    if (table.Rows.Count >= 0)
                    {
                        row = table.Rows[0];
                        tdt.Sid = Convert.ToInt32(row["Sid"]);
                        tdt.EmpSid = Convert.ToInt32(row["EmpSid"]);
                        tdt.BankSid = Convert.ToInt32(row["BankSid"]);
                        tdt.PaymentDate = Convert.ToString(row["PaymentDate"]);
                        tdt.PaymentAmount = Convert.ToDecimal(row["PaymentAmount"]);
                        tdt.PaymentDD = Convert.ToString(row["PaymentDD"]);
                        tdt.PaymentMM = Convert.ToString(row["PaymentMM"]);
                        tdt.PaymentYY = Convert.ToString(row["PaymentYY"]);
                        tdt.OrgSid = Convert.ToInt32(row["OrgSid"]);
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return tdt;
        }

        public DataTable GetList()
        {
            DataTable table = null;
            try
            {
                try
                {
                    string strSql = "select * from tEmpPayment";
                    table = base.ExecuteForDataTable(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return table;
        }
    }
}

